#include <stdio.h>
#include <stdlib.h>
#include <windows.h>

int main(void)
{
	int i, j;
	int x = 1, y = 5;
	int top = 1, bottom = 10, left = 1, right = 20;
	int velocity_x = 1, velocity_y  = 1;
	
	while ( 1 )
	{
		x += velocity_x;
		y += velocity_y;
		
		system("cls");
		for ( i = top-1; i < x; i++ )
		{
			if ( i == top-1 )
			{
				for ( j = left-1; j <= right+1; j++)
					printf("*");
				printf("\n");
			}
			else
			{
				printf("*");
				for ( j = left; j <= right; j++)
					printf(" ");
				printf("*\n");
			}
		}
		for ( i = left-1; i < y; i++ )
		{
			if ( i == left-1 )
				printf("*");
			else
				printf(" ");
		}
		
		printf("o");
		for ( i += 1 ; i <= right+1; i++ )
		{
			if ( right+1 == i )
				printf("*\n");
			else
				printf(" ");
		}
		for ( i = x+1; i <= bottom+1; i++ )
		{
			if ( i == bottom+1 )
			{
				for ( j = left-1; j <= right+1; j++)
					printf("*");
				printf("\n");
			}
			else
			{
				printf("*");
				for ( j = left; j <= right; j++)
					printf(" ");
				printf("*\n");
			}
		}
		
		Sleep(50);
		if ( x == bottom || x == top )
		{
			printf("\a");
			velocity_x = -velocity_x;
		}
		if ( y == right || y == left )
		{
			printf("\a");
			velocity_y = -velocity_y;
		}
	}
	
	return 0;
}